#define _CRT_SECURE_NO_WARNINGS 1
#include <climits>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int Min = INT_MAX;
bool prime(int x)
{
    if (x < 2) return false;
    for (int i = 2;i <= sqrt(x);i++)
    {
        if (x % i == 0) return false;
    }
    return true;
}
bool recursion(vector<vector<int>>& vv, map<int, bool> ma, int lev, int maxlev, int ret)
{
    if (lev == maxlev)
    {
        if (ret < Min) Min = ret;
        cerr << "end" << endl;
        return true;
    }
    bool flag = true;
    bool re = false;
    //cerr<<vv[lev].size()<<endl;
    for (int i = 0;i < vv[lev].size();i++)
    {
        for (auto a : ma) cerr << a.first << ":" << a.second << ", ";
        cerr << endl;
        if (ma[vv[lev][i]] == true)
        {
            cerr << "lev=" << lev << "  " << vv[lev][i] << "  " << endl;
            auto tmpma = ma;
            tmpma[vv[lev][i]] = false;
            flag = false;
            if (recursion(vv, tmpma, lev + 1, maxlev, ret + vv[lev][i]))
            {
                re = true;
            }
        }
    }
    if (flag)
    {
        cerr << "rfalse" << endl;
        return false;
    }
    return re;
}
int main()
{
    int n = 0;
    cin >> n;
    vector<vector<int>> vv;
    map<int, bool> ma;
    for (int i = 0;i < n;i++)
    {
        int tmp = 0;
        cin >> tmp;
        cerr << "tmp=" << tmp << endl;
        vector<int> v;
        for (int i = 2;i <= tmp;i++)
        {
            if (tmp % i == 0 && prime(i))
            {
                cerr << "push:" << i << " ";
                v.push_back(i);
                ma[i] = true;
            }
        }
        cerr << endl;
        vv.push_back(v);
    }
    for (auto a : vv)
    {
        for (auto b : a) cerr << b << " ";
        cerr << endl;
    }
    cerr << "----------------" << endl;
    bool ret = recursion(vv, ma, 0, n, 0);
    if (!ret)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << Min << endl;
    }
    return 0;
}
